import React from "react";

class Demo extends React.Component {
  constructor(props) {
    super(props);
    this.login = this.login.bind(this);


    this.state = {
      person: {
        username: "laohu",
        age: 1000
      },
      isLogin: false,
      cartList: [{ name: "小猪" }, { name: "小狗" }, { name: "小羊" }]
    };
  }

  render() {
    let { person, cartList, isLogin } = this.state;
    return (
      <div>
        {isLogin ? <p>用户名: 13800000000  <button onClick={this.login}>退出</button></p> : <button onClick={this.login}>立即登录</button>}
      </div>
    );
  }

  login() {
    console.log(this);
    this.setState({
      isLogin: !this.state.isLogin
    })
  }
}

export default Demo;
